package com.rchat.pocmini.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

/**
 * Created by ljd on 2017/3/4.
 */

public class SharedPreferenceUtil {

    public static final String IS_REMEMBER_PWD = "remember_pwd";
    public static final String IS_AUTO_LOGIN = "auto_login";

    public static void saveWithKeyValue(Context context, String key, Object value) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("rchat", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();//获取编辑器
        if (value instanceof String) {
            editor.putString(key, (String) value);
        }
        if (value instanceof Integer) {
            editor.putInt(key, (int) value);
        }
        if (value instanceof Boolean) {
            editor.putBoolean(key, (Boolean) value);
        }
        editor.apply();//提交修改 
    }

    public static String getStringValueWithKey(Context context, String key) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("rchat", Context.MODE_PRIVATE);
        String value = sharedPreferences.getString("key", "");
        return value;
    }

    public static int getIntValueWithKey(Context context, String key) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("rchat", Context.MODE_PRIVATE);
        int value = sharedPreferences.getInt("key", 0);
        return value;
    }

    public static boolean getBooleanValueWithKey(Context context, String key) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("rchat", Context.MODE_PRIVATE);
        boolean value = sharedPreferences.getBoolean("key", false);
        return value;
    }
}
